///////////////////////////////////////////////////////////////////////////////
//
//  startplayer.js   			version 1.0
//
//  This file is provided by Microsoft as a helper file for websites that
//  incorporate Silverlight Objects. This file is provided under the Silverlight 
//  SDK 1.0 license available at http://go.microsoft.com/fwlink/?linkid=94240.  
//  You may not use or distribute this file or the code in this file except as 
//  expressly permitted under that license.
// 
//  Copyright (c) 2007 Microsoft Corporation. All rights reserved.
//
///////////////////////////////////////////////////////////////////////////////



function get_mediainfo(mediainfoIndex) {
    switch (mediainfoIndex) {        

        case 0:
            return  { "mediaUrl": "http://download.microsoft.com/download/2/c/4/2c433161-f56c-4bab-bbc5-b8c6f240afcc/PARTNER_1280x720_2000_128.wmv",
                      "placeholderImage": "",
                      "chapters": [    
                                        { "title": "[Unknown Value]",   "time": 8.9113932,     "imageUrl": "assets/media/PARTNER_1280x720_2000_128_MarkerThumb 00.00.08.9113932.jpg"} ,    
                                        { "title": "[Unknown Value]",   "time": 50.7351763,     "imageUrl": "assets/media/PARTNER_1280x720_2000_128_MarkerThumb 00.00.50.7351763.jpg"} ,    
                                        { "title": "[Unknown Value]",   "time": 72.7748338,     "imageUrl": "assets/media/PARTNER_1280x720_2000_128_MarkerThumb 00.01.12.7748338.jpg"} ,    
                                        { "title": "[Unknown Value]",   "time": 122.3213101,     "imageUrl": "assets/media/PARTNER_1280x720_2000_128_MarkerThumb 00.02.02.3213101.jpg"} ,    
                                        { "title": "[Unknown Value]",   "time": 154.5316604,     "imageUrl": "assets/media/PARTNER_1280x720_2000_128_MarkerThumb 00.02.34.5316604.jpg"}                
                                  ] };                                                                
                          
        default:
             throw Error.invalidOperation("No such mediainfo");
     }
}

function StartWithParent(parentId, appId) {
    new StartPlayer_0(parentId);
}

function StartPlayer_0(parentId) {
    
    this._hostname = EePlayer.Player._getUniqueName("xamlHost");
    Silverlight.createObjectEx( {   source: 'XAML/player.xaml', 
                                        parentElement: $get(parentId ||"divPlayer_0"), 
                                        id:this._hostname, 
                                        properties:{ width:'100%', height:'100%', version:'1.0', background:document.body.style.backgroundColor, isWindowless:'true' }, 
                                        events:{ onLoad: Function.createDelegate(this, this._handleLoad) } } );
    this._currentMediainfo = 0;
         
}
StartPlayer_0.prototype= {
    _handleLoad: function(sender, eventArgs) {
    
        this._player = $create(   ExtendedPlayer.Player, 
                                  { // properties
                                    autoPlay    : true, 
                                    volume      : 1.0,
                                    muted       : false
                                  }, 
                                  { // event handlers
                                    mediaEnded: Function.createDelegate(this, this._onMediaEnded),
                                    mediaFailed: Function.createDelegate(this, this._onMediaFailed)
                                  },
                                  null, $get(this._hostname) ); 
    /*var slPlugin = $get(this._hostname);

    // Create a Downloader object.
    var downloader = slPlugin.createObject("downloader");

    // Add DownloadProgressChanged and Completed events.
    downloader.addEventListener("downloadProgressChanged", this._onDownloadProgressChanged);
    downloader.addEventListener("completed", this._onCompleted);

    // Initialize the Downloader request.
    // NOTE: downloader APIs disallow file:\\ scheme
    // you must run this sample over localhost: or off a server or the following call will fail

    downloader.open("GET", "http://download.microsoft.com/download/2/c/4/2c433161-f56c-4bab-bbc5-b8c6f240afcc/SL_PARTNER_1280x720_2000_128.wmv");

    // Execute the Downloader request.
    downloader.send();
    },
    
    // Event handler for updating visual progress indicator
_onDownloadProgressChanged: function(sender, eventArgs)
{

    // Calculate the downloaded percentage.
    var percentage = Math.floor(sender.downloadProgress * 100);

    // Update the Rectangle and TextBlock objects of the visual progress indicator.
    alert(percentage + "%");
    //progressRectangle.width = percentage * 2; 
},

    _onCompleted: function(sender, eventArgs)
{
    // Retrieve the Image object.
    var myImage = sender.findName("VideoWindow");

    // Set the Source property to the contents of the downloaded object,
    // In this case, since the downloaded content represents a single image file, promo.png,
    // the part parameter is set to an empty string.
    myImage.setSource(sender, "");
    

            
        */ 
        this._playNextVideo();
        //alert("hi")
     
    },    
    _onMediaEnded: function(sender, eventArgs) {
        window.setTimeout( Function.createDelegate(this, this._playNextVideo), 1000);
    },
    _onMediaFailed: function(sender, eventArgs) {
        alert(String.format( Ee.UI.Xaml.Media.Res.mediaFailed, this._player.get_mediaUrl() ) );
    },
    _playNextVideo: function() {
        var cVideos = 1;
        if (this._currentMediainfo<cVideos)
            this._player.set_mediainfo( get_mediainfo( this._currentMediainfo++ ) );    
    }        
}
